/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.ubdx1.jacomode.models;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;
import java.util.ArrayList;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.DatasetProducer;
import de.laures.cewolf.links.CategoryItemLinkGenerator;
import de.laures.cewolf.tooltips.CategoryToolTipGenerator;



/**
 * An example data producer.
 * @author  Guido Laures
 */
public class BarChartModel implements DatasetProducer, CategoryToolTipGenerator, CategoryItemLinkGenerator, Serializable {

        private static final long serialVersionUID = 1L;

    private static final Log log = LogFactory.getLog(BarChartModel.class);
    // These values would normally not be hard coded but produced by
    // some kind of data source like a database or a file
	
	private final String[] seriesNames = {"§§§§§§§§§§§!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"};
        private int part; //numero de la partie de la liste complète à splitter
        private int width;
        private ArrayList<Integer> x;
        private ArrayList<Integer> y;
        
    /**
     *  Produces some random data.
     */
    @Override
    public Object produceDataset(Map params) throws DatasetProduceException {
        log.debug("producing data.");
        DefaultCategoryDataset dataset = new DefaultCategoryDataset() {

            /**
             * @see java.lang.Object#finalize()
             */
            @Override
            protected void finalize() throws Throwable {
                super.finalize();
                log.debug(this + " finalized.");
            }
        };

        ArrayList<Integer>categories = new ArrayList<Integer>();
        categories = (ArrayList<Integer>)params.get("categories");
        ArrayList<Integer> repeat = new ArrayList<Integer>();
        repeat = (ArrayList<Integer>)params.get("repeat");
        
        for (int i = 0; i < categories.size(); i++) {
            dataset.addValue(repeat.get(i), seriesNames[0], String.valueOf( (int) categories.get(i)));
        }
        return dataset;
    }

    /**
     * This producer's data is invalidated after 5 seconds. By this method the
     * producer can influence Cewolf's caching behaviour the way it wants to.
     */
    @Override
    public boolean hasExpired(Map params, Date since) {
        log.debug(getClass().getName() + "hasExpired()");
        return (System.currentTimeMillis() - since.getTime()) > 5000;
    }

    /**
     * Returns a unique ID for this DatasetProducer
     */
    @Override
    public String getProducerId() {
        return "PageViewCountData DatasetProducer";
    }

    /**
     * Returns a link target for a special data item.
     */
    @Override
    public String generateLink(Object data, int series, Object category) {
        return seriesNames[series];
    }

    /**
     * @see java.lang.Object#finalize()
     */
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        log.debug(this + " finalized.");
    }

    /**
     * @see org.jfree.chart.tooltips.CategoryToolTipGenerator#generateToolTip(CategoryDataset, int, int)
     */
    @Override
    public String generateToolTip(CategoryDataset arg0, int series, int arg2) {
        return seriesNames[series];
    }

    public void setWidth(int width){
        this.width = width;
    }

    public void setPart(int part){
        this.part = part;
    }

    public void setX(ArrayList<Integer> x){
        this.x = x;
    }

    public void setY(ArrayList<Integer> y){
        this.y = y;
    }

    public int getWidth(){
        return width;
    }

    public int getPart(){
        return part;
    }

    public ArrayList<Integer> getX(){
        return x;
    }

    public ArrayList<Integer> getY(){
        return y;
    }
}


